package cn.tqfeiyang.smartadmin.business.organization.controller;

import cn.tqfeiyang.smartadmin.business.organization.constant.DepartmentConstants;
import cn.tqfeiyang.smartadmin.business.organization.service.DepartmentExcelService;
import cn.tqfeiyang.smartadmin.business.organization.request.DepartmentQueryDTO;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.tqfeiyang.smartadmin.commons.response.ApiResult;
import cn.tqfeiyang.smartadmin.commons.logging.OperationLog;

/**
 * 部门Excel控制器
 *
 * @author tqfeiyang
 * @since 2024-10-18
 */
@RestController
@Validated
@RequestMapping(DepartmentConstants.REQUEST_URL)
@Tag(name = DepartmentConstants.API_TAG)
public class DepartmentExcelController {

    /**
     * 部门Excel服务
     */
    @Resource
    private DepartmentExcelService departmentExcelService;

    /**
     * 导出部门Excel
     */
    @OperationLog
    @GetMapping("/exportDepartmentsToExcel")
    @Operation(summary = "部门 - 导出部门Excel")
    @SaCheckPermission(DepartmentConstants.PERMISSION + "exportDepartmentsToExcel")
    public void exportDepartmentsToExcel(@Validated DepartmentQueryDTO dto) {
        departmentExcelService.exportDepartmentsToExcel(dto);
    }

    /**
     * 下载部门模板
     */
    @OperationLog
    @GetMapping("/downloadDepartmentTemplate")
    @Operation(summary = "部门 - 下载部门模板")
    @SaCheckPermission(DepartmentConstants.PERMISSION + "downloadDepartmentTemplate")
    public void downloadDepartmentTemplate() {
        departmentExcelService.downloadDepartmentTemplate();
    }

    /**
     * 导入部门Excel
     */
    @OperationLog
    @PostMapping("/importDepartmentsFromExcel")
    @Operation(summary = "部门 - 导入部门Excel")
    @SaCheckPermission(DepartmentConstants.PERMISSION + "importDepartmentsFromExcel")
    public ApiResult importDepartmentsFromExcel(MultipartFile file) {
        departmentExcelService.importDepartmentsFromExcel(file);
        return ApiResult.success();
    }
}
